<include file="public@header" />
</head>

<body>
	<div class="wrap js-check-wrap">
		<ul class="nav nav-tabs">
			<?php $currentTab = 2 ;?>
			<include file="public/../company/nav" />
		</ul>   
		<form class="well form-inline margin-top-20" method="post" action="">
			公司列表
            <select class="form-control" name="company" onchange="selectCompany(this);">
                <option value="0">请选择公司</option>
                <volist name="companyList" id="vo">
                    <option value="{$vo.id}" <?php if($vo['id'] == $companyId){ echo 'selected'; }?> >{$vo.company_name}</option>
                </volist>
            </select>
            搜索菜单
            <input type="text" name="keywords" class="form-control" >
            <button type="button" class="btn btn-success" name="search" value="search" onclick="serchMenu();">查询</button>
        </form>    
            <table class="table table-bordered">
                <thead>
                    <tr>
                        <th  style="text-align: center;"  width="50">序号</th>
                        <th  style="text-align: center;" >原始菜单规则</th>
                        <th  style="text-align: center;" >原始菜单名称</th>
                        <th  style="text-align: center;" >菜单别名</th>
                        <th  style="text-align: center;"  width='100'>操作</th>
                    </tr>
                </thead>
                <tbody class='project-type-tbody'>
                    <volist name='menuList' id='vo'>
                    <tr>
                        <td><?php echo ++$key;?></td>
                        <td class="rule_name">{$vo.app}/{$vo.controller}/{$vo.action}</td>
                        <td class="menu_name">{$vo.name}</td>
                        <td id='typeName-{$vo.id}'>{$vo.alias}</td>
                        <td><a class="btn btn-success btn-sm project-type-edit" data-tag="{$vo.id}">编辑</a><!-- <a href="{:url('company/deleteAlias')}?id={$vo.id}" class="btn btn-danger btn-sm js-ajax-delete" data-msg='确定要删除菜单别名吗？'>清除别名</a> --></td>
                    </tr>
                    </volist>
                </tbody>
            </table>
        <empty name="menuList">
            无配置~
        </empty>
	</div>

	<script src="__STATIC__/js/admin.js"></script>
    <script src="__STATIC__/js/layer/layer.js"></script>
<script>

</script>
<script>

    //编辑项目分类
    $(document).on('click','.project-type-edit',function(){
        if($('.edit-input').length>0){
           return false; 
        }
        var id=$(this).data('tag');
        var text=$('#typeName-'+id).text();
        var input='<input style="width:200px;display:inline;" class="form-control edit-input" value="'+text+'" />  <a class="btn btn-primary btn-sm edit-save-btn" data-tag="'+id+'">保存</a> <a class="btn btn-default btn-sm remove-edit-input">取消</a>';
        $('#typeName-'+id).html(input);
    })
    //编辑项目分类取消
    $(document).on('click','.remove-edit-input',function(){
        var text=$('.edit-input').val();
        $(this).parent().html(text);
    });
    //编辑内容保存
    $(document).on('click','.edit-save-btn',function(){
        var text=$.trim($('.edit-input').val());
        var companyId = '{$companyId}';
        $.get("{:url('company/editMenuAlias')}?id="+$(this).data('tag')+"&type="+text+"&companyId="+companyId,function(data){
            data=JSON.parse(data);
            var icon=(data.code!=200)?5:1;
            layer.msg(data.message,{icon:icon});
            if(data.status=='success'){
                setTimeout(function(){
                    window.location.reload();
                },1200);
            }
        });
    });
</script>

<script type="text/javascript">
//
var selectCompany = function(_this){
    var  value = $(_this).val();
    if(value == 0){
        return false;
    }
    window.location.href = "{:url('company/setMenuAlias')}?companyId="+value;
}

var serchMenu = function(){
    var keywords = $.trim($('input[name=keywords]').val());
    $('.project-type-tbody tr').each(function(){
        var name = $(this).find('.menu_name').text();
        var rule = $(this).find('.rule_name').text();
        $(this).css('display','');
        if( name.indexOf(keywords) ==-1 && rule.indexOf(keywords) ==-1 ){
            $(this).css('display','none');
        }
    });
}
</script>
</body>
</html>